/*    */ package com.cr.common.utils;
/*    */ 
/*    */ import com.cr.common.core.domain.entity.SysUser;
/*    */ import com.cr.common.utils.bean.MyBeanUtils;
/*    */ import org.apache.shiro.SecurityUtils;
/*    */ import org.apache.shiro.crypto.SecureRandomNumberGenerator;
/*    */ import org.apache.shiro.session.Session;
/*    */ import org.apache.shiro.subject.PrincipalCollection;
/*    */ import org.apache.shiro.subject.SimplePrincipalCollection;
/*    */ import org.apache.shiro.subject.Subject;
/*    */ 
/*    */ public class ShiroUtils {
/*    */   public static Subject getSubject() {
/* 21 */     return SecurityUtils.getSubject();
/*    */   }
/*    */   
/*    */   public static Session getSession() {
/* 26 */     return SecurityUtils.getSubject().getSession();
/*    */   }
/*    */   
/*    */   public static void logout() {
/* 31 */     getSubject().logout();
/*    */   }
/*    */   
/*    */   public static SysUser getSysUser() {
/* 36 */     SysUser user = null;
/* 37 */     Object obj = getSubject().getPrincipal();
/* 38 */     if (MyStringUtils.isNotNull(obj)) {
/* 40 */       user = new SysUser();
/* 41 */       MyBeanUtils.copyBeanProp(user, obj);
/*    */     } 
/* 43 */     return user;
/*    */   }
/*    */   
/*    */   public static void setSysUser(SysUser user) {
/* 48 */     Subject subject = getSubject();
/* 49 */     PrincipalCollection principalCollection = subject.getPrincipals();
/* 50 */     String realmName = principalCollection.getRealmNames().iterator().next();
/* 51 */     SimplePrincipalCollection simplePrincipalCollection = new SimplePrincipalCollection(user, realmName);
/* 53 */     subject.runAs((PrincipalCollection)simplePrincipalCollection);
/*    */   }
/*    */   
/*    */   public static Long getUserId() {
/* 58 */     return Long.valueOf(getSysUser().getUserId().longValue());
/*    */   }
/*    */   
/*    */   public static String getLoginName() {
/* 63 */     return getSysUser().getLoginName();
/*    */   }
/*    */   
/*    */   public static String getIp() {
/* 68 */     return getSubject().getSession().getHost();
/*    */   }
/*    */   
/*    */   public static String getSessionId() {
/* 73 */     return String.valueOf(getSubject().getSession().getId());
/*    */   }
/*    */   
/*    */   public static String randomSalt() {
/* 82 */     SecureRandomNumberGenerator secureRandom = new SecureRandomNumberGenerator();
/* 83 */     String hex = secureRandom.nextBytes(3).toHex();
/* 84 */     return hex;
/*    */   }
/*    */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\lib\creditorRights-common-4.7.0.jar!\com\cr\commo\\utils\ShiroUtils.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */